package yxy.cherry.battle.module.affix.buff;

import yxy.cherry.battle.Battle;
import yxy.cherry.battle.Fighter;
import yxy.cherry.battle.module.affix.*;
import yxy.cherry.battle.module.record.stream.RecordStream41TriggerBuff;
import yxy.cherry.data.bean.skill;

import java.util.ArrayList;

/**
 * @author James
 * 奇谋(原为感伤)（目标每有一个负面状态，施法者对目标造成的伤害增加X%，伤害增加最高不超过X%）
 * @date 2022/2/25 12:06
 **/
@BuffType(Type = AffixFactory.BuffTypeEnum.奇谋)
public class Affix75CleverStrategy extends Buff {
    public Affix75CleverStrategy(Fighter source, Fighter target, skill skilldata, int[] params) {
        super(source, target, skilldata, params);
    }

    private int getAppointBuffTypeStr() {return getParam(0);}
    private int getAddPer() { return getParam(1);}
    private int getAddPerMax() { return getParam(2);}

    @Override
    public boolean exec(Fighter source, Fighter target) {
        ArrayList<Integer> arrays = UtilTool.Integer2List(getAppointBuffTypeStr());

        AffixContext.AffixAction affixAction = getAffixAction();
        AffixContext.AffixTarget affixTarget = affixAction.getTarget(affixAction.get针对目标());

        int number = 0;
        for (int appointType:arrays){
            number = number + affixTarget.get目标().getDownSideStateNumber(BuffType.forNumber(appointType));
        }
        int addPer = Math.min(getAddPer()*number,getAddPerMax());

        ArrayList<Long> 伤害流 = affixTarget.get伤害流();
        ArrayList<Long> 结算伤害流 = genFinalDamage(伤害流, affixTarget.getBaseDamageList(), addPer);

        Battle.battleLogger(6,"奇谋：施法者"+source.getName()+"目标："+target.getName()+"异常状态"+getAppointBuffTypeStr()+"数量"+number+"原始伤害："+伤害流.toString()+"基本伤害："+affixTarget.getBaseDamageList().toString()+"最终伤害："+结算伤害流.toString());
        affixTarget.set伤害流(结算伤害流);

        getRecord().stream(new RecordStream41TriggerBuff(source,source.getBuffMap().get(getBuffCodeSeq()))).record();


        return true;
    }

    @Override
    public BuffType getBuffType() {
        return BuffType.增益效果;
    }

    @Override
    public BuffStateType getBuffStateType() {
        return BuffStateType.sadState;
    }

}
